<template>
  <div class="ceshi-container">
    <h1>主进程接口测试页面</h1>
    
    <div class="test-section">
      <h2>应用信息测试</h2>
      <div class="button-group">
        <button @click="getAppVersion" class="test-btn">获取应用版本</button>
        <button @click="getAppName" class="test-btn">获取应用名称</button>
        <button @click="getPlatform" class="test-btn">获取平台信息</button>
      </div>
      <div class="result-display">
        <h3>测试结果：</h3>
        <pre>{{ appInfo }}</pre>
      </div>
    </div>

    <div class="test-section">
      <h2>窗口操作测试</h2>
      <div class="button-group">
        <button @click="minimizeWindow" class="test-btn">最小化窗口</button>
        <button @click="maximizeWindow" class="test-btn">最大化窗口</button>
      </div>
      <div class="result-display">
        <h3>操作状态：</h3>
        <p>{{ windowStatus }}</p>
      </div>
    </div>

    <div class="test-section">
      <h2>系统通知测试</h2>
      <div class="button-group">
        <button @click="showNotification" class="test-btn">显示通知</button>
      </div>
      <div class="result-display">
        <h3>通知状态：</h3>
        <p>{{ notificationStatus }}</p>
      </div>
    </div>

    <div class="test-section">
      <h2>批量测试</h2>
      <button @click="runAllTests" class="test-btn primary">运行所有测试</button>
      <div class="result-display">
        <h3>批量测试结果：</h3>
        <pre>{{ allTestsResult }}</pre>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Ceshi',
  data() {
    return {
      appInfo: '点击按钮开始测试...',
      windowStatus: '等待操作...',
      notificationStatus: '等待操作...',
      allTestsResult: '等待批量测试...'
    }
  },
  mounted() {
    console.log('Ceshi 页面已加载，可以开始测试主进程接口')
  },
  methods: {
    async getAppVersion() {
      try {
        const version = await window.electronAPI.getAppVersion()
        this.appInfo = `应用版本: ${version}`
        console.log('获取应用版本成功:', version)
      } catch (error) {
        this.appInfo = `获取应用版本失败: ${error.message}`
        console.error('获取应用版本失败:', error)
      }
    },

    async getAppName() {
      try {
        const name = await window.electronAPI.getAppName()
        this.appInfo = `应用名称: ${name}`
        console.log('获取应用名称成功:', name)
      } catch (error) {
        this.appInfo = `获取应用名称失败: ${error.message}`
        console.error('获取应用名称失败:', error)
      }
    },

    getPlatform() {
      try {
        const platform = window.electronAPI.getPlatform()
        this.appInfo = `平台: ${platform}`
        console.log('获取平台信息成功:', platform)
      } catch (error) {
        this.appInfo = `获取平台信息失败: ${error.message}`
        console.error('获取平台信息失败:', error)
      }
    },

    async minimizeWindow() {
      try {
        await window.electronAPI.minimize()
        this.windowStatus = '窗口最小化成功'
        console.log('窗口最小化成功')
      } catch (error) {
        this.windowStatus = `窗口最小化失败: ${error.message}`
        console.error('窗口最小化失败:', error)
      }
    },

    async maximizeWindow() {
      try {
        await window.electronAPI.maximize()
        this.windowStatus = '窗口最大化成功'
        console.log('窗口最大化成功')
      } catch (error) {
        this.windowStatus = `窗口最大化失败: ${error.message}`
        console.error('窗口最大化失败:', error)
      }
    },

    async showNotification() {
      try {
        await window.electronAPI.showNotification('测试通知', '这是一个来自主进程的测试通知')
        this.notificationStatus = '通知发送成功'
        console.log('通知发送成功')
      } catch (error) {
        this.notificationStatus = `通知发送失败: ${error.message}`
        console.error('通知发送失败:', error)
      }
    },

    async runAllTests() {
      this.allTestsResult = '开始运行所有测试...\n'
      
      try {
        const version = await window.electronAPI.getAppVersion()
        const name = await window.electronAPI.getAppName()
        const platform = window.electronAPI.getPlatform()
        
        this.allTestsResult += `应用版本: ${version}\n`
        this.allTestsResult += `应用名称: ${name}\n`
        this.allTestsResult += `平台: ${platform}\n`
        
        await window.electronAPI.showNotification('批量测试完成', '所有测试已成功运行')
        this.allTestsResult += '\n✅ 所有测试完成！'
        
      } catch (error) {
        this.allTestsResult += `\n❌ 测试过程中出现错误: ${error.message}`
      }
    }
  }
}
</script>

<style scoped>
.ceshi-container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.test-section {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.button-group {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.test-btn {
  background: #007bff;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
}

.test-btn.primary {
  background: #28a745;
  font-size: 16px;
}

.result-display {
  background: white;
  border: 1px solid #dee2e6;
  border-radius: 5px;
  padding: 15px;
}

.result-display pre {
  background: #f8f9fa;
  padding: 10px;
  border-radius: 4px;
  white-space: pre-wrap;
}
</style>